package main

import (
	"fmt"
	"log"
	"strconv"
	"time"
)

const ymd = "2006-01-02"
const ymdhis = "2006-01-02 15:04:05"

func main() {
	time := time.Now().Unix()
	// fmt.Println(time)
	// fmt.Println(reflect.TypeOf(time)) // 打印数据类型
	// timeLayout := "2006-01-02"
	timeLayout := "2006-01-02 15:04:05"
	fmt.Println(stringToTimeStamp("2012-12-12 13:01:59", timeLayout))
	fmt.Println("当前日期为 ", fmtDate(time, ymdhis))
	fmt.Println("当前为 ", week(time))
}

/**
 * 字符串转时间戳
 * @return string
 */
func stringToTimeStamp(strTime string, timeLayout string) int64 {
	loc, _ := time.LoadLocation("Local")
	the_time, err := time.ParseInLocation(timeLayout, strTime, loc)
	if err != nil {
		log.Println("StringToTimeStamp出现异常：", err)
	}
	unix_time := the_time.Unix()
	return unix_time
}

/**
 * 时间戳转成日期（12小时制）
 * @return string
 */
func fmtDate(timestamp int64, timeLayout string) string {
	tm := time.Unix(timestamp, 0)
	r := tm.Format(timeLayout)

	return r
}

/**
 * 周
 * @return string
 */
func week(timestamp int64) string {
	var WeekDayMap = map[string]string{
		"Monday":    "一",
		"Tuesday":   "二",
		"Wednesday": "三",
		"Thursday":  "四",
		"Friday":    "五",
		"Saturday":  "六",
		"Sunday":    "日",
	}

	day, _ := time.Parse("2006-01-02", strconv.FormatInt(timestamp, 10))
	dayStr := day.Weekday().String()

	r := "周" + WeekDayMap[dayStr]

	return r
}

/**
 * 指定年的月份列表
 * @return string
 */
func monthList(year string) string {
	return ""
}

// fmt.Println(WeekDayMap[dayStr])
// fmt.Println(strconv.FormatInt(timestamp, 10))
// fmt.Println(reflect.TypeOf(strconv.FormatInt(timestamp, 10)))
// ymd := time.Parse("2006-01-02", strconv.FormatInt(timestamp, 10))
// weekInt := ymd.Weekday().String()
